# -*- coding: utf-8 -*- 
# @project : 《Atcoder》
# @Author : created by bensonrachel on 2021/6/22
# @File : C - Traveling Salesman around Lake.py

K, N = list(map(int,input().split()))
rate = [int(i) for i in input().split()]
char = []
for i in range(len(rate)-1):
    char.append(rate[i+1]-rate[i])
a = rate[-1]-rate[0]
char.append(K-a)
max_num = max(char)
print(K-max_num)
"""
基本思想：
找出环上所有相邻点之间距离的最大值，然后用K减去这个最大值即为答案。
 the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.
 其中，第一个点和最后一个点的距离怎么求呢，用最后一个点的值减去第一个点的值，再用K减去这个值即为“第一个点和最后一个点的距离”
 https://atcoder.jp/contests/abc160/tasks/abc160_c
"""